package com.tencent.sr.iris.basic.mp.dependency.activity;


import com.alibaba.fastjson.JSON;
import com.tencent.sr.iris.activity.interfaces.client.activity.UserTaskRecordClient;
import com.tencent.sr.iris.activity.interfaces.client.activity.UserTaskStaticClient;
import com.tencent.sr.iris.activity.interfaces.request.IrisPaginationRequest;
import com.tencent.sr.iris.activity.interfaces.request.acticity.*;
import com.tencent.sr.iris.activity.interfaces.response.activity.*;
import com.tencent.sr.iris.basic.mp.common.util.HttpUtils;
import com.tencent.sr.rmall.common.primitive.HttpResult;
import com.tencent.sr.rmall.common.response.PaginationResponse;
import com.tencent.sr.rmall.springbootstarter.authtoken.localbean.AppUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author nixiaolin
 * @date 2022/11/7 14:37
 */
@Slf4j
@Component
public class UserTaskDependency {

    @Resource
    private AppUser appUser;

    @Resource
    UserTaskRecordClient userTaskRecordClient;

    @Resource
    UserTaskStaticClient userTaskStaticClient;

    /**
     * 会员任务情况分页列表
     * @param request
     * @return
     */
    public PaginationResponse<UserTaskRecordResponse> page(IrisPaginationRequest<UserTaskRecordRequest> request) {
        request.getQueryCriteria().setUid(appUser.getUid());
        HttpResult<PaginationResponse<UserTaskRecordResponse>> result = userTaskRecordClient.page(request);
        return HttpUtils.handleError(result);
    }

    /**
     * 余额流水活动信息
     *
     * @param request
     * @return
     */
    public FlowActivityInfoResponse queryFlowActivityInfo(FlowActivityInfoRequest request) {
        request.setUid(appUser.getUid());
        log.info("调用UserTaskDependency.queryFlowActivityInfo，入参：{}", JSON.toJSONString(request));
        HttpResult<FlowActivityInfoResponse> result = userTaskRecordClient.queryFlowActivityInfo(request);
        log.info("调用UserTaskDependency.queryFlowActivityInfo，入参：{}，返回：{}", JSON.toJSONString(request), JSON.toJSONString(result));
        return HttpUtils.handleError(result);
    }

    /**
     * 长期激励统计
     * @param request
     * @return
     */
    public LongTermAwardStaticResponse longTermAward(LongTermAwardStaticRequest request) {
        request.setUid(appUser.getUid());
        HttpResult<LongTermAwardStaticResponse> result = userTaskStaticClient.longTermAward(request);
        return HttpUtils.handleError(result);
    }

    /**
     * 用户活动信息
     * @return
     */
    public UserActivityInfoResponse userActivityInfo() {
        UserActivityInfoRequest request = new UserActivityInfoRequest();
        request.setUid(appUser.getUid());
        log.info("调用UserTaskDependency.userActivityInfo，入参：{}", JSON.toJSONString(request));
        HttpResult<UserActivityInfoResponse> result = userTaskStaticClient.userActivityInfo(request);
        log.info("调用UserTaskDependency.userActivityInfo，入参：{}，返回：{}", JSON.toJSONString(request), JSON.toJSONString(result));
        return HttpUtils.handleError(result);
    }

    /**
     * 统计所有活动奖励金信息（预估，实际，待确认等）
     *
     * @param staticRequest
     * @return
     */
    public ActivityStaticResponse activityStatic(ActivityStaticRequest staticRequest) {
        staticRequest.setUid(appUser.getUid());
        log.info("调用UserTaskDependency.activityStatic，入参，uid：{}，reqParam：{}", appUser.getUid(), JSON.toJSONString(staticRequest));
        HttpResult<ActivityStaticResponse> result = userTaskStaticClient.activityStatic(staticRequest);
        log.info("调用UserTaskDependency.activityStatic，出参：uid：{}，respParam：{}", appUser.getUid(), JSON.toJSONString(result));
        return HttpUtils.handleError(result);
    }

    public PaginationResponse<UserTaskRecordResponse> getJuniorTaskRecordList(IrisPaginationRequest<GetJuniorTaskRecordListRequest> listRequestIrisPaginationRequest) {
        listRequestIrisPaginationRequest.getQueryCriteria().setPid(appUser.getUid());
        log.info("调用UserTaskDependency.getJuniorTaskRecordList，入参，uid：{}，reqParam：{}", appUser.getUid(), JSON.toJSONString(listRequestIrisPaginationRequest));
        HttpResult<PaginationResponse<UserTaskRecordResponse>> result = userTaskRecordClient.getJuniorTaskRecordList(listRequestIrisPaginationRequest);
        log.info("调用UserTaskDependency.getJuniorTaskRecordList，出参：uid：{}，respParam：{}", appUser.getUid(), JSON.toJSONString(result));
        return HttpUtils.handleError(result);
    }
}
